package cn.lagou

object StationTimeSum {

  case class UserInfo(userName: String, location: String, startTime: Int, duration: Int)

  def main(args: Array[String]): Unit = {
    val userInfoList: List[UserInfo] = List(
      UserInfo("UserA", "LocationA", 8, 60),
      UserInfo("UserA", "LocationA", 9, 60),
      UserInfo("UserB", "LocationB", 10, 60),
      UserInfo("UserB", "LocationB", 11, 80)
    )
    val usersMap: Map[String, List[UserInfo]] = userInfoList.groupBy(t => t.userName + "," + t.location)
    val sumMap = usersMap.mapValues(list => (list.sortWith(_.startTime < _.startTime).head.startTime, list.map(_.duration).sum))
    val tuples = sumMap.map(x => (x._1.split(",")(0), x._1.split(",")(1), x._2._1, x._2._2))
    tuples.foreach(println)
  }
}
